<template>
<page>
  <div class="wrapper">
    <head :title="Tname"></head>
    <div class="btnav">
      <image class="tabImg" :src="imgurl" />
      <div class="btnav-con">
        <text class="btnav-con-tit">{{Tname}}</text>
        <text class="btnav-con-item">{{total}} item</text>
      </div>
    </div>

    <div class="pageContent">
      <list class="listMode">
        <refresh class="loadingMore" @refresh="onrefresh" :display="refreshing ? 'show' : 'hide'">
          <loading-indicator class="indicators"></loading-indicator>
        </refresh>
        <cell class="recontent" v-if="shopList.length>0">
          <div class="reitem" v-for="(item,index) in shopList" :key="index">
            <image
              class="goodsImg"
              :src="item.thumb"
              @click="gonext('root:app/goods/goods.js',{id:item.id})"
            />
            <div class="contentBox">
              <text class="goodsTitle2">{{item.title}}</text>
              <div class="priceInfo">
                <div class="leftInfo">
                  <text class="symbol">AU$</text>
                  <text class="money">{{item.price}}</text>
                </div>
                <div class="leftInfo">
                  <!-- <text class="iconfont shopIcon">&#xe64c;</text>
                <text class="iconfont shopIcon">&#xe634;</text>
                  <text class="iconfont shopIcon">&#xe607;</text>-->
                </div>
              </div>
            </div>
          </div>
        </cell>
        <cell>
          <empty
            v-if="shopList.length==0&&!isLoading"
            tips="No results found"
            img="root:img/e_seel.png"
          ></empty>
        </cell>
        <loading
          class="loadingMore"
          v-if="hasMore"
          @loading="onloadmore"
          :display="loadinging ? 'show' : 'hide'"
        >
          <loading-indicator class="indicators"></loading-indicator>
        </loading>
      </list>
    </div>
    <div class="maskClack" @click="e=>e.stopPropagation()" v-if="isLoading">
      <floading class="indicator" color="#303030"></floading>
    </div>
  </div>
</page>
</template>

<script>
const navbar = weex.requireModule("navbar");

import asCore from "../../mixin/core";
import { get_goods_list } from "../../mixin/ajax.js";
export default {
  data() {
    return {
      Tname: "",
      imgurl: "",
      total:0,
      pageType: "search",
      amount: 0,
      shopList: [],
      searchList: "",
      categoryid: "",
      searchVal: "",
      keywords: "",
      setype: "0,1",
      page: 1,
      refreshing: false,
      hasMore: true,
      loadinging: false
    };
  },
  computed: {
    searchArr() {
      if (!this.searchList) {
        return [];
      }
      return this.searchList.split(",");
    }
  },
  methods: {
    onLoad(parmars) {
      if (parmars && parmars.parmar) {
        return false;
      }

      if (parmars) {
        if (parmars.types) {
          this.setype = parmars.types;
        }
        if (parmars.keywords) {
          this.keywords = parmars.keywords;
        }
        if (parmars.name) {
          this.Tname = parmars.name;
          this.imgurl = parmars.img;
          if (parmars.id) {
            this.categoryid = parmars.id;
          }
          this.searchRet(parmars.name);
        }
      }
    },
    onloadmore() {
      if (this.hasMore) {
        this.page++;
        this.searchRet();
      }
    },
    onrefresh(event) {
      var s = this;
      s.refreshing = true;
      let that = this;
      that.searchRet();
      setTimeout(() => {
        s.refreshing = false;
      }, 1000);
    },
    backPage() {
      this.back();
    },

    gonext(url, parmar) {
      this.push(url, parmar);
    },

    searchRet(name) {
      this.isLoading = true;
      this.loadinging = true;
      let that = this;

      get_goods_list(
        {
          users_id: "",
          keywords: this.keywords,
          categoryid: this.categoryid,
          type: this.setype,
          status: "1",
          page: this.page,
          page_num: "10"
        },
        (res, flag) => {
          this.isLoading = false;
          if (flag) {
            if (res.code == "200") {
              // that.shopList = res.data.list;
              this.total=res.data.total;
              if (this.page == 1) {
                that.shopList = res.data.list;
              } else {
                that.shopList = that.shopList.concat(res.data.list);
              }
              this.loadinging = false;
              if (res.data.list.length < 10) {
                this.hasMore = false;
              }
            } else {
              that.toast(res.message);
            }
          }
        }
      );
    }
  }
};
</script>

<style scoped lang="less">
.wrapper {
  background-color: #ffffff;
  flex: 1;
}

.pageContent {
  flex: 1;

  width: 750px;
}
.leftBox {
  align-items: center;
  flex-direction: row;
  flex: 1;
  justify-content: center;
}
.indicators {
  margin-top: 20px;
  margin-bottom: 20px;
  height: 80px;
  width: 80px;
  color: #303030;
}
.arricon {
  font-size: 40px;
  font-family: iconfont;
  color: #303030;
}
.rightBox {
  align-items: center;
  flex-direction: row;
  flex: 1;

  &:active {
    background-color: #f2f2f2;
  }
}
.historyMode {
  width: 750px;
}
.maskClack {
  position: fixed;
  left: 0;
  bottom: 0;
  right: 0;
  top: 0;
  justify-content: center;
  align-items: center;
  background-color: transparent;
}
.indicator {
  width: 40px;
  height: 40px;
}
.listMode {
  width: 750px;
  flex: 1;
  background-color: #f2f2f2;
}

.hisTop {
  flex-direction: row;
  padding: 24px 32px;
  justify-content: space-between;
  align-items: center;
}

.hisItem {
  flex-direction: row;
  flex-wrap: wrap;
  padding: 32px;
}

.itemLi {
  margin-right: 20px;
  margin-bottom: 24px;
  height: 55px;
  line-height: 55px;
  padding: 0 40px;
  background-color: #e6e6e6;
  border-radius: 55px;
  color: #666666;
}

.hisTit {
  font-size: 28px;
  color: #000000;
}

.hisDel {
  font-size: 30px;
  color: #999999;
}

.inputbox {
  overflow: hidden;
  background-color: #fff;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  border-radius: 40px;
  height: 58px;
  padding: 0 40px;
  margin-right: 20px;
  border-width: 1px;
  border-style: solid;
  border-color: #e1e1e1;
  /* margin-left: 32px; */
}

.iconfont {
  font-family: iconfont;
}

.btnav {
  width: 750px;
  height: 165px;
  background-color: rgba(255, 255, 255, 1);
  flex-direction: row;
  align-items: center;
  padding: 0 15px;
  &-con {
    height: 90px;
    justify-content: center;
    padding-left: 20px;
    &-tit {
      height: 45px;
      font-size: 32px;
      font-family: PingFangSC-Medium, PingFangSC;
      font-weight: 500;
      color: rgba(30, 30, 30, 1);
      line-height: 45px;
    }
    &-item {
      height: 30px;
      font-size: 22px;
      font-family: PingFangSC-Regular, PingFangSC;
      font-weight: 400;
      color: rgba(30, 30, 30, 1);
      line-height: 30px;
    }
  }
}

.tabImg {
  width: 90px;
  height: 90px;
}

.searchIcon {
  font-family: iconfont;
  color: #fff;
  background-color: #303030;
  line-height: 58px;
  height: 58px;
  width: 88px;
  border-radius: 30px;
  text-align: center;
  font-size: 30px;
}

.tips {
  height: 58px;
  font-size: 28px;
  flex: 1;
}

.Cancel {
  font-size: 26px;
  color: #fff;
  background-color: #303030;
  line-height: 48px;
  height: 48px;
  width: 88px;
}
.loadingMore {
  width: 750;
  display: -ms-flex;
  display: -webkit-flex;
  display: flex;
  -ms-flex-align: center;
  -webkit-align-items: center;
  -webkit-box-align: center;
  align-items: center;
}
.scroller {
  flex: 1;
}

.recontent {
  width: 750px;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 24px;
  /* background-color: #000000; */
}

.reitem {
  height: 516px;
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: #fff;
  border-radius: 10px;
  /* justify-content: space-between; */
}

.goodsImg {
  width: 336px;
  height: 336px;
}

.contentBox {
  width: 336px;
  padding: 0 20px;
}

.goodsTitle {
  font-size: 20px;
  height: 56px;
  line-height: 28px;
  margin-top: 12px;
  color: #1e1e1e;
  text-overflow: ellipsis;
  lines: 2;
}

.goodsTitle2 {
  font-size: 26px;
  height: 74px;
  line-height: 37px;
  margin-top: 16px;
  color: #1e1e1e;
  text-overflow: ellipsis;
  lines: 2;
}

.priceInfo {
  margin-top: 20px;
  flex-direction: row;
  justify-content: space-between;
}

.leftInfo {
  flex-direction: row;
  align-items: flex-end;
}

.symbol {
  color: red;
  margin-right: 5px;
}

.money {
  color: red;
  font-size: 32px;
  font-weight: bold;
  margin-right: 5px;
}

.shopIcon {
  font-size: 32px;
  margin-left: 10px;
}
</style>
